package com.beemans.common.app

import android.app.Application
import android.content.ComponentCallbacks2
import android.content.Context
import android.content.res.Configuration
import com.blankj.utilcode.util.Utils
import com.tiamosu.fly.base.delegate.IFlyAppLifecycles
import com.tiamosu.fly.imageloader.glide.GlideFly

/**
 * @author tiamosu
 * @date 2021/3/12
 */
class AppLifecyclesImpl : IFlyAppLifecycles {
    override fun attachBaseContext(context: Context) {}
    override fun onCreate(application: Application) {}
    override fun onTerminate(application: Application) {}
    override fun onConfigurationChanged(configuration: Configuration) {}

    override fun onLowMemory() {
        GlideFly.get(Utils.getApp()).clearMemory()
    }

    override fun onTrimMemory(level: Int) {
        if (level == ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN) {
            GlideFly.get(Utils.getApp()).clearMemory()
        }
        GlideFly.get(Utils.getApp()).trimMemory(level)
    }
}